//
//  RootController.m
//  TrainTree
//
//  Created by wanghui on 2017/8/24.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "RootController.h"
#import "StudyController.h"
#import "CourseController.h"
#import "MineController.h"

@interface RootController ()<UITabBarControllerDelegate>

@end

@implementation RootController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:@"loginSuccess" object:nil];

    [self addControllers];
}

- (void)addControllers
{
    StudyController *studyVc = [[StudyController alloc] init];
    [self setChildVc:studyVc  title:@"学习" NormalImage:@"learningNor" selectImage:@"learningSel"];

    CourseController *courseVc = [[CourseController alloc] init];
    [self setChildVc:courseVc title:@"课程" NormalImage:@"coursesNor" selectImage:@"coursesSel"];

    MineController *mineVc = [[MineController alloc] init];
    [self setChildVc:mineVc title:@"我的" NormalImage:@"mineNor" selectImage:@"mineSel"];
    self.selectedViewController = [self.viewControllers objectAtIndex:1];
}

- (void)loginSuccess
{
    self.selectedViewController = [self.viewControllers objectAtIndex:1];
//    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"loginSuccess" object:nil];

}
- (void)setChildVc:(UIViewController *)childVc title:(NSString *)title NormalImage:(NSString *)normalImage selectImage:(NSString *)selectImage
{
    childVc.title = title;
    [childVc.tabBarItem setImage:[ImageNamed(normalImage) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [childVc.tabBarItem setSelectedImage:[ImageNamed(selectImage) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:childVc];
    nav.navigationBarHidden = YES;
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor
                                                                                         colorWithRed:164.0/255.0 green:164.0/255.0 blue:164.0/255.0 alpha:1.0]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor
                                                                                         colorWithRed:74.0/255.0 green:74.0/255.0 blue:74.0/255.0 alpha:1.0]} forState:UIControlStateSelected];
    [self addChildViewController: nav];
}

 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
